import {Component, OnInit, Output, EventEmitter} from '@angular/core';
import {HomeService} from '@app/services/home.service';

@Component({
  selector: 'app-home-history',
  templateUrl: './history.component.html',
  styleUrls: ['./history.component.less'],
})
export class HistoryComponent implements OnInit {
  initLoading = false;
  histories = [];

  constructor(private homeService: HomeService) {
  }

  @Output() history = new EventEmitter<any>();

  ngOnInit(): void {
    this.refresh();
  }

  sendHistory(item): void {
    console.log(item);
    this.history.emit(item);
  }

  selectStart(): boolean {
    return false;
  }

  refresh(): void {
    this.initLoading = true;
    this.homeService.history_list().subscribe(
      (resp) => {
        this.initLoading = false;
        this.histories = resp.data;

        console.log(resp);
      },
      (error) => {
        this.initLoading = false;
        console.log(error);
      }
    );
  }
  clearAll(): void {
    this.initLoading = true;

    this.homeService.history_clear().subscribe(
      (resp) => {
        console.log(resp);
        this.initLoading = false;
        this.histories = [];
      },
      (error) => {
        this.initLoading = false;
        console.log(error);
      }
    );
  }
}
